package com.haois.mp.wechat.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by haol on 2017/8/18.
 */
@Component
public class HyperText {
    private Logger logger = LoggerFactory.getLogger(HyperText.class);
    private String head = "http";

    public String getValue(HttpServletRequest request) {
        String url = head + "://" + request.getServerName() //服务器地址
                + request.getContextPath()      //项目名称
                + request.getServletPath()      //请求页面或其他地址
                + (request.getQueryString() == null ? "" : "?" + request.getQueryString()); //参数
        logger.info("HyperText获取的地址为[{}]", url);
        return url;
    }

    public static String getHttpValue(HttpServletRequest request) {
        String url = "http://" + request.getServerName() //服务器地址
                + request.getContextPath()      //项目名称
                + request.getServletPath()      //请求页面或其他地址
                + (request.getQueryString() == null ? "" : "?" + request.getQueryString()); //参数
        System.out.println("logger.info(\"HyperText获取的地址为:" + url);
        return url;
    }
}
